const Review = require('../model/reviewModel');
const catchAsync = require('../utils/catchAsync');
const AppError = require("../utils/appError");
const factory = require("./handleFactory");
exports.getAllReview =catchAsync(async(req, res,next) => {
    console.log(req.params.tourId,'聚合参数1')
    let filter ={}
    if(req.params.tourId) filter = {tour:req.params.tourId};
    const review = await Review.find(filter);
    
    // 发送回复
    res.status(200).json({
        status: 'success',
        results: review.length,
        data: {
            review
        }
    })
})
exports.setTourUserIds = (req,res,next)=>{
    if(!req.body.tour) req.body.tour = req.params.tourId;
    if(!req.body.user) req.body.user = req.user.id
    next();
}

exports.createReview = factory.createOne(Review);
exports.deleteReview = factory.deleteOne(Review);
exports.updateReview = factory.updateOne(Review);
exports.getReview = factory.getOne(Review);